package com.bawei.mall.pay.controller;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradeWapPayRequest;
import com.alipay.api.response.AlipayTradeWapPayResponse;

/**
 * @Author：HaoYunde
 * @Package：com.bawei.mall.pay.controller
 * @Project：mall_cloud
 * @name：Alipay
 * @Date：2024/7/10 16:08
 */
public class Alipay {
    public static void main(String[] args) {
        AlipayClient alipayClient = new DefaultAlipayClient(
                "https://openapi-sandbox.dl.alipaydev.com/gateway.do",
                "9021000139609731",
                "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCUSKYd2sNIsVO3Sw/XkFnPJ+wy180KekYmSJk6MbT34idaDM+IL5PIUwb0YdUr543BqLEOpmYlyUR76d/p588IDSwcnBYvLW9G4i8mVOJT4Q/Z9PU+2i1CoafxbqpAMKBupIdCJ985PKOXnlMoAiI6ie77QpoWrgxg/xloqe2dS/jS8PFBZ6pqm9Nbu3BstDyBv1FZfM2QMR3o0OXIZWTdaKarRSSS+Wd291WAIG0vxxrkNr/T0C8bYnqefhB2tJyNPzbf/0d0xNPeK2PZwzML+bakd3w7u6YqDsVi+OjzmCs0zVDFQVoY7+Af1JrtUVd2qbMVB2BdsSk+RgkeEljHAgMBAAECggEAf9fu2Hh+u5KfIb1miCydMZwy6VbjIbBwAJvA98pZQwpJcTrwRnL2j9T9fv9GIdc+gYPmO0I9eUCAefEWqvy/oypwKK5t9fjPIqbpjbvLchPtbbXjJ3BFa1giimYmBLen6hyRvPjRXPCp/pNzEGBekGfRkfFHFlyysYHerz0qbtz64Q+Ed+9WaSFd2oleud8laPxYp/G1oTXT4o7DfKzQHcUhWwxf9/BdeSPJjvrru5VqUtg7/ZD1xVmULGI74kQQke2g7u0FgHgL/NaOlDjQJk4dk3ep+EMLPGa/CFXkTM4rkiDgEmvBlDgc2GTluaaQDpVASx4612FMLkHrR4dEcQKB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WxROCvR4jF9vT0p1u9R5mxqZ3S3LD+57ZPA5RP/pIwEmF1UTLEsdqbWiDL5YVGxNjxAzgoL6iBEfg8unEv6Wks0otpdIIuFlYoC84J/BxTL9kdvWPINYo7F6P7iukYo6xNWgxkdxKA1Uw6NTAtqZr7v72qRm9m9kt7xxkYGBNDqakno+1CyGXmLJ/Iclgh3xt6b/M9bIYsBVPwIDAQAB",
                "RSA2"
        );

        AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
        request.setNotifyUrl("");// 异步接收地址
        request.setReturnUrl("");// 同步跳转地址

        // 必传参数
        JSONObject bizContent = new JSONObject();
        bizContent.put("out_trade_no", "20210817010101004"); // 商户订单号
        bizContent.put("total_amount", 0.01); // 支付金额
        bizContent.put("subject", "测试商品"); // 订单标题

        // 可选参数
        bizContent.put("product_code", "QUICK_WAP_WAY"); // 手机网站支付默认传值QUICK_WAP_WAY

        request.setBizContent(bizContent.toString());

        AlipayTradeWapPayResponse response = null;
        try {
            response = alipayClient.pageExecute(request, "POST");
        } catch (AlipayApiException e) {
            throw new RuntimeException(e);
        }
        String pageRedirectionData = response.getBody();
        System.out.println(pageRedirectionData);

        if (response.isSuccess()) {
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
        }
    }

}
